package test.singleton;

// ConCurrentLazy1不够懒 https://www.jianshu.com/p/6189034c6984
public class ConCurrentLazy {
    // 对Instance使用volatile修饰即可，可以禁止指令重排序。
    private static volatile ConCurrentLazy singleton;
    private ConCurrentLazy() {}

    public static ConCurrentLazy getInstance() {
        if (singleton == null) {
            synchronized (ConCurrentLazy.class) {
                if (singleton == null) {
                    singleton = new ConCurrentLazy();
                }
            }
        }
        return singleton;
    }
}
